package validation;

import java.util.Hashtable;
import java.util.LinkedList;
//import file.SearchRecord;
import utility.Input;
import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class Isvalue implements Validation 
{
	DBManager database;
	String VALUE="value";
	GetIdName gid;
	//SearchRecord sr;
	RecordSearch ps;
	LinkedList<Object>linelist = new LinkedList<Object>();
	
	
	public String getMessage()
	{
		return "The value must be from "+linelist;
	}

	public void setDbmanager(DBManager database) 
	{
		this.database = database;
		gid = new GetIdName(database);
		VALUE =  gid.getId(VALUE);
	}
	
	public boolean validate(String Value) 
	{
		return false;
	}
	
	public boolean validate(String actualvalue, String ValidateValue) 
	{
		ValidateValue = gid.getId(ValidateValue);
		//String path = Input.MASTERREPORTSPATH  + ValidateValue + "//" +ValidateValue + "_mid" + Input.FILRFORMAT;
		//sr = new SearchRecord(path);
		Hashtable<Object, Object>table = new Hashtable<Object, Object>();
		table.put("mid", ValidateValue);
		table.put("pid",VALUE);
		/*sr.fileOpen();
		String line[] = sr.getRecordSet(table);
		sr.fileClose();*/
		ps = new RecordSearch(database);
		ps.setConditionMap(table);
		table.put("td","null");
		String line[] = ps.getArrayFromResultSet();
		
		for(int i=0;i<line.length;i++)
		{
			String Splitline[] = line[i].split("\t");
			String value=Splitline[Column.pv_index-1];
			if(value.equals("0"))
				value = Splitline[Column.vt_index-1];
			else
				value = gid.getItem(value.toLowerCase());
			linelist.add(value.toLowerCase());
		}
		if(!linelist.contains(actualvalue.toLowerCase())) 
		{
	  	 return false ;
		}
			
		else
		{
	  		return true;
		}
		
	}
	
	public boolean validate(String Value, String ConditionValue, String Refvalue) 
	{
		return validate(Value, ConditionValue);
	}

	public void setBasicvalue(String value) {
		// TODO Auto-generated method stub
		
	}
}
